﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RepairListCtrl.ascx.cs" Inherits="WebUI.Controls.RepairListCtrl" %>


<script type="text/javascript">
    var <%=ClientID %>clickOnCheckbox;
    var <%=ClientID %>selectedRow = null;       
    var <%=ClientID %>selectedCheckbox = null; 
    var <%=ClientID %>selectedID = null; 
    var <%=ClientID %>selectedClass = null; 
    
    function resetGridSelection<%=ClientID %>(){
        <%=ClientID %>selectedRow = null;   
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;          
        <%=ClientID %>selectedCheckbox = null; 
        <%=ClientID %>selectedID = null; 
        <%=ClientID %>selectedClass = null; 
    }
    
    function clickOnCheckBox<%=ClientID %>(cb){
        <%=ClientID %>clickOnCheckbox = true;
    }
    
    function onItemClick<%=ClientID %>(sender)
    {
        var hidSelectedID = document.getElementById("<%= hidSelectedID.ClientID %>");
        if(<%=ClientID %>clickOnCheckbox){
            <%=ClientID %>clickOnCheckbox = false;
            return;
        }

        if(<%=ClientID %>selectedRow == null){
            <%=ClientID %>selectedRow = document.getElementById("<%=ClientID %>" + "_row_" + hidSelectedID.value);
        }
        
        if(<%=ClientID %>selectedRow != null){
            if(<%=ClientID %>selectedRow.className)
                <%=ClientID %>selectedRow.className = <%=ClientID %>selectedRow.getAttribute("orgclass");
            else
                <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;
            else{
                var chks = <%=ClientID %>selectedRow.getElementsByTagName("input");
                 for(var i = 0; i < chks.length; i++){
                    if(chks[i].type == "checkbox" && chks[i].id.indexOf("cbSelect") >= 0){
                        chks[i].checked = false;
                        break;
                    }
                }
            }
        }
        
        if(sender.className){
            sender.className = "CustomGridSelectedItem";
        }
        else{
            <%=ClientID %>selectedClass = sender.getAttribute("class");
            sender.setAttribute("class", "CustomGridSelectedItem");
        }
        <%=ClientID %>selectedRow = sender;
        
        var inputs = sender.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
                <%=ClientID %>selectedCheckbox = inputs[i];
                inputs[i].checked = true;
                break;
            }
        }

        hidSelectedID.value = <%=ClientID %>selectedRow.getAttribute("ItemID");
    }
    
    function selectAll<%=ClientID %>(cbAll){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"){
                inputs[i].checked = cbAll.checked;
            }
        }
    }
    
    function getSelectedItemID<%=ClientID %>(){
        if(document.getElementById("<%= hidSelectedID.ClientID %>").value == "")
            return null;
        return document.getElementById("<%= hidSelectedID.ClientID %>").value;
    }

    function showPrintDlg(key) {
        var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
    }

    function onInvoiceNo_click(lnk){
        var hidInvoiceID = document.getElementById("<%= hidInvoiceID.ClientID %>");     
        hidInvoiceID.value = lnk.getAttribute('ItemID');
    }

    
    function doNothing(id){
        return false;
    }

    function HasCheckedItems<%=ClientID %>(){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        var ok = false;
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"  && inputs[i].id.indexOf("cbSelect") >= 0 && inputs[i].checked == true ){
                ok = true;
            }
        }
        return ok;
    }

    function changeLoanPhone(id){
        var returnValue = window.showModalDialog('<%= this.ResolveClientUrl("~/EditPages/ChangeLoanPhone.aspx?key=" + this.SourceObjectSessionID + "&id=") %>' + id, '', 'dialogWidth=400px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');
        return returnValue > 0;
    }
</script>



<%--start modify here--%>
<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None" class="customGrid" ShowHeader="false"
    AutoGenerateColumns="false" EmptyDataText="No record to display" ItemStyle-Wrap="true" CellPadding="0" CellSpacing="0"
    OnSortCommand="grid_OnSortCommand" OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound"
    OnPageIndexChanged="grid_OnPageIndexChanged" AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
    <PagerStyle Mode="NumericPages" PageButtonCount="10"   />
    <Columns>
        <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' />
            </ItemTemplate>
            <ItemStyle VerticalAlign="Top" />
        </asp:TemplateColumn>
        
        <asp:TemplateColumn HeaderText="">
            <ItemStyle VerticalAlign="Top" />
            <ItemTemplate>
                <table width="100%" style="vertical-align:top">
                    <tr>
                        <td style='width:100px; text-align:left; vertical-align:top'>
                            <asp:Label class="labelBarCode" ID="lblRepairNo" runat="server" Text='<%# "R" + Eval("RepairNo") %>' ></asp:Label>
                            <br /> 
                            <div class='labelBarCode'><asp:Literal  ID="litRepairNo" runat="server" Text='<%# POSSystem.BLL.Utilities.GenerateBarCode(Eval("RepairNo").ToString()) %>' ></asp:Literal></div>
                            <asp:Label class="labelBarCode" ID="lblCreatedDate" runat="server" Text='<%# ((DateTime)Eval("CreatedDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) %>' ></asp:Label>
                        </td>
                        
                        <td style='width:450px; text-align:left; vertical-align:top;'>
                            <asp:Label class="labelMessage0" ID="Label6" runat="server" Text='<%# Eval("BrandName") %>' ></asp:Label>
                            <asp:Label class="labelMessage0" ID="Label7" runat="server" Text='<%# Eval("ModelName") %>' ></asp:Label>
                            <asp:Label class="labelMessage0" ID="Label10" runat="server" Text='<%# "[" + Eval("IMEI") + "]" %>' ></asp:Label>
                            <br />
                            <asp:Label class="labelHint" ID="Label12" runat="server" Text='<%# Eval("Accessories").ToString().Replace(",", ", ") %>' ></asp:Label>
                            <asp:Literal ID="Label14" runat="server" Text='<%# Eval("LoanPhoneID") != DBNull.Value ? ((Eval("LoanPhoneReturn") != DBNull.Value && (bool)Eval("LoanPhoneReturn") == true) ? "<span style=\"text-decoration:line-through\" >" : "") + "<br/><span class=\"labelHint\"><b>Loan phone:</b> " + Eval("LoanPhoneName").ToString() + "[" + Eval("LoanPhoneIMEI").ToString() + "]</span>" + ((Eval("LoanPhoneReturn") != DBNull.Value && (bool)Eval("LoanPhoneReturn") == true) ? "</span>" : "") : "" %>' ></asp:Literal>
                            <div style='height:3px'>&nbsp;</div>
                            <div class='customhyperlink' style="padding-top:2px; border-top-color:Green; border-top-style:dotted; border-top-width:1px;" ><asp:Literal ID="litProblems" runat="server" Text='<%# GetProblems(Eval("ID")) %>' ></asp:Literal></div>
                        </td>
                        
                        <td style='text-align:center; vertical-align:top'>
                            <div>
                                <asp:Label class="labelMessage0" ID="Label8" runat="server" Text='<%#  Eval("CustomerName").ToString() != "" ? Eval("CustomerName") : "CASH" %>' ></asp:Label>
                                <br />
                                <asp:LinkButton OnClick="btnChangeLoanPhone_OnClick" OnClientClick='<%# AllowUpdating &&  POSSystem.BLL.Branches.CurrentBranchID == SessionUser.BranchID ? "return changeLoanPhone(" + Eval("ID").ToString() + ");" : "return false;" %>' runat="server" >
                                    <asp:Label ToolTip="Click to Add/Remove Loan Phone" class="labelMessage0" ID="Label9" runat="server" Text='<%# Eval("CustomerPhone") %>' ></asp:Label>
                                </asp:LinkButton>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td style='text-align:left; vertical-align:top'>
                            <br style="line-height:6px" />
                            <div >
                                <asp:Label class="labelBarCode" ID="Label4" runat="server" Text='Box: ' ></asp:Label>
                                
                                <span class='customhyperlink'>
                                    <asp:Literal ID="Label2" runat="server" Text='<%# GetRepairBox(Eval("RepairBox"), Eval("RepairBoxID"), Eval("ID")) %>' ></asp:Literal>
                                </span>
                            </div>
                        </td>
                        <td style='text-align:left; vertical-align:top'>
                            <br style="line-height:6px" />
                            <asp:Label class="hintBold" ID="Label3" runat="server" Text='Repair Status:' ></asp:Label>     
                            <br />
                            <div class="labelNote1" style="padding-left:4px" ><asp:Literal ID="Literal1" runat="server" Text='<%# GetRepairStatus(Eval("ID")) %>' ></asp:Literal></div>
                            <br style="line-height:6px" />
                            <asp:Label class="hintBold" ID="Label5" runat="server" Text='Technician Note:' ></asp:Label>     
                            <br />
                            <div class="labelNote1" style="padding-left:4px" ><asp:Literal ID="Literal2" runat="server" Text='<%# Eval("Note") %>' ></asp:Literal></div>
                        </td>
                         <td style='text-align:center; vertical-align:top'>
                            <asp:Button Visible='<%# AllowUpdating &&  POSSystem.BLL.Branches.CurrentBranchID == SessionUser.BranchID %>' ID="btnUpdateStatus" Text="Update Status" runat="server" OnClientClick='<%# string.Format("return {1}({0});", Eval("ID"), ClientOnUpdateStatusPrototype) %>' />
                            <div style='height:10px'>&nbsp;</div>
                            <asp:Label class="labelMessage1" ID="Label11" runat="server" Text='<%# Eval("StatusName") %>' ></asp:Label>   
                            <br />
                            <asp:Label class="hintBold" ID="Label13" runat="server" Text='<%# IsJobReturned(Eval("StatusID")) ?  "as" : "" %>' ></asp:Label>
                            <br />
                            <asp:Label class="labelMessage1" ID="Label1" runat="server" Text='<%# RepairedOrUnrepaired(Eval("StatusID"), Eval("InvoiceID")) %>' ></asp:Label>
                         </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="" Visible = "false">
            <ItemStyle VerticalAlign="Middle" />
            <ItemTemplate>
                <asp:Button Width="80px" ID="btnCallCustomer" Text='<%# Eval("StatusName") %>' runat="server" OnClientClick='<%# string.Format("return {1}({0});", Eval("ID"), ClientOnCallCustomerPrototype) %>' />
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>
<asp:HiddenField ID="hidInvoiceID" runat="server" />
<asp:HiddenField ID="hidSelectedID" runat="server" />